﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BizTalk.ESB.Extensions.Helpers
{
    [Serializable]
    public class ServiceProxyInstructions
    {
        private const string TracePrefix = "[ItineraryServiceProxy] ";

        public String ProcessName { get; set; }
        public String StepName { get; set; }

        public Boolean DebugFlag { get; set; }
        public Boolean IsFaultPublished { get; set; }

        public String RequestMapTypeName { get; set; }
        public String ResponseMapTypeName { get; set; }
        public MapSourceType ResponseMapOption { get; set; }
        public Boolean ResponseIsValid { get; set; }
        public BreUseMsgOption ResponseResolverMessage { get; set; }
        public bool MergeContext { get; set; }

        public String RoutingServiceName { get; set; }
        public String RoutingServiceType { get; set; }
        public String RoutingServiceAction { get; set; }
        public Boolean RoutingIsRequestResponse { get; set; }
        public Int32 RoutingTimeoutHours { get; set; }
        public Int32 RoutingTimeoutMinutes { get; set; }
        public Int32 RoutingTimeoutSeconds { get; set; }

        public ValidationType ValidationMethod { get; set; }
        public Boolean ValidationFlag { get; set; }
        public String ValidationPolicyName { get; set; }
        public String ValidationPolicyVersion { get; set; }
        public String ValidationDocType { get; set; }
        public String ValidationBreTrace { get; set; }
        public String ValidationXsdType { get; set; }

        public Int32 RetrySeconds { get; set; }
        public Int32 Retries { get; set; }

        public Boolean StopOnError { get; set; }
        public Boolean HasError { get; set; }
        public Boolean ServiceCallSucceeded { get; set; }
        public Boolean HasNextStep { get; set; }

        public ServiceProxyInstructions()
        {
            ServiceCallSucceeded = false;
            StopOnError = true;
            HasError = false;
            ResponseIsValid = false;

            ResponseMapTypeName = System.String.Empty;
            ValidationFlag = false;
            ValidationMethod = BizTalk.ESB.Extensions.Helpers.ValidationType.None;
            ValidationPolicyName = System.String.Empty;
            ValidationPolicyVersion = System.String.Empty;
            ValidationXsdType = System.String.Empty;
            ValidationDocType = System.String.Empty;
            ResponseMapOption = BizTalk.ESB.Extensions.Helpers.MapSourceType.Original;
        }

        public void TraceItineraryService(string BizTalkServiceName, string BizTalkServiceID)
        {
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ProcessName: " + this.ProcessName, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "StepName: " + this.StepName, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "StopOnError: " + this.StopOnError.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Retries: " + this.Retries.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "RetrySeconds: " + this.RetrySeconds.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "HasNextStep: " + this.HasNextStep.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "RoutingIsRequestResponse: " + this.RoutingIsRequestResponse.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "RoutingTimeoutHours: " + this.RoutingTimeoutHours.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "RoutingTimeoutMinutes: " + this.RoutingTimeoutMinutes.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "RoutingTimeoutSeconds: " + this.RoutingTimeoutSeconds.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "HasError: " + this.HasError.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ServiceCallSucceeded: " + this.ServiceCallSucceeded.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ResponseResolverMessage: " + this.ResponseResolverMessage.ToString(), System.Diagnostics.EventLogEntryType.Information));
        }

        public void TraceRequest(string BizTalkServiceName, string BizTalkServiceID)
        {
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Routing Service Name: " + this.RoutingServiceName, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Routing Service Type: " + this.RoutingServiceType, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Routing Action: " + this.RoutingServiceAction, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Is Request-Response: " + this.RoutingIsRequestResponse.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Request Transform Type: " + this.RequestMapTypeName, System.Diagnostics.EventLogEntryType.Information));
        }

        public void TraceResponse(string BizTalkServiceName, string BizTalkServiceID)
        {
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ResponseMapTypeName: " + this.ResponseMapTypeName, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ResponseIsValid: " + this.ResponseIsValid.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ResponseMapOption: " + this.ResponseMapOption.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationFlag: " + this.ValidationFlag.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationMethod: " + this.ValidationMethod.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationPolicyName: " + this.ValidationPolicyName, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationXsdType: " + this.ValidationXsdType, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationBreTrace: " + this.ValidationBreTrace, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationDocType: " + this.ValidationDocType, System.Diagnostics.EventLogEntryType.Information));
        }

        public void TraceCompleteItineraryStep(string BizTalkServiceName, string BizTalkServiceID)
        {
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Proxy Info - Service Call Succeeded = " + this.ServiceCallSucceeded.ToString(), System.Diagnostics.EventLogEntryType.Information));

            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Proxy Info - Stop On Error = " + this.StopOnError.ToString(), System.Diagnostics.EventLogEntryType.Information));

            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Proxy Info - Has Next Step = " + this.HasNextStep.ToString(),  System.Diagnostics.EventLogEntryType.Information));
        }

        public void TracePreviewNextItineraryStep(string BizTalkServiceName, string BizTalkServiceID, string NextServiceName, string NextServiceState, string NextServiceType)
        {
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Publishing Message to Itinerary to process the following Itinerary Step...", System.Diagnostics.EventLogEntryType.Information));

            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Service Name: " + NextServiceName, System.Diagnostics.EventLogEntryType.Information));

            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Service State: " + NextServiceState, System.Diagnostics.EventLogEntryType.Information));

            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Service Type: " + NextServiceType, System.Diagnostics.EventLogEntryType.Information));

            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "Has Next Step: " + this.HasNextStep.ToString(), System.Diagnostics.EventLogEntryType.Information));
        }

        public void TraceValidationInfo(string BizTalkServiceName, string BizTalkServiceID)
        {
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationBreTrace = " + this.ValidationBreTrace, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationDocType = " + this.ValidationDocType, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationFlag = " + this.ValidationFlag.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationMethod = " + this.ValidationMethod.ToString(), System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationPolicyName = " + this.ValidationPolicyName, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationPolicyVersion = " + this.ValidationPolicyVersion, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationXsdType = " + this.ValidationXsdType, System.Diagnostics.EventLogEntryType.Information));
        }

        public void TraceValidationOutput(string BizTalkServiceName, string BizTalkServiceID, string ValidationProcessName, string ValidationResult)
        {
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationProcessName = " + ValidationProcessName, System.Diagnostics.EventLogEntryType.Information));
            System.Diagnostics.Trace.WriteLineIf(this.DebugFlag,
                DebugMessageFactory.GenerateTraceMessage(BizTalkServiceName, BizTalkServiceID
                    , TracePrefix + "ValidationResult = " + ValidationResult, System.Diagnostics.EventLogEntryType.Information));
        }
    }
}
